data<-read.csv("figure4.csv",header=T,as.is=T)

data<-data[data$party_code==200 |data$party_code==100,]
data <- data[data$chamber=="House",]
data$total[is.na(data$total)] <-0
data$Party <- factor(data$party_code, labels=c("Democrat","Republican"))

data$congress <- as.factor(data$congress)
data <-data[!is.na(data$nominate_congress),]

a <- data %>%
	group_by(nominate_congress) %>%
	summarise(mean=mean(prop))

p<-ggplot(data, aes(x=nominate_dim1, y=prop,group=Party, weight=total)) + 
	theme_bw() + 
	xlab("") + 
	ylab("Proportion of Speeches\nEngaging Bipartisanship")+
	geom_point(alpha = .05, aes(size=total, color=Party))  + 
	stat_smooth(method="loess",aes(fill = Party,color=Party))  + 
	theme_pew() +
	scale_colour_manual(values=c("blue","red")) + 
	scale_fill_manual(values=c("blue","red"))+ 
	facet_wrap(~ nominate_congress, ncol = 2) + 
	theme(legend.position = "none") + 
	geom_vline(xintercept = c(0),color="black") +
	geom_hline(aes(yintercept=mean), data=a, color="gray") 
p

ggsave(filename="f4.pdf", plot=p,width=6,height=8)
